package cn.jiahua.hospital.config;

import lombok.Data;
import lombok.ToString;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.FileWriter;
import java.io.IOException;

@Data
@Component
@ToString
@ConfigurationProperties(prefix = "alipay")
public class AliPayConfig {
    // 商户appid
    private String appid = "";
    // 私钥 pkcs8格式的
    private String rsaPrivateKey= "";
    // 服务器异步通知页面路径 需http://或者https://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
    private String notifyUrl = "";
    // 页面跳转同步通知页面路径 需http://或者https://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问 商户可以自定义同步跳转地址
    private String returnUrl = "";
    // 请求网关地址
    private String url = "";
    // 编码
    private String charset = "";
    // 返回格式
    private String format = "";
    // 支付宝公钥
    private String alipayPublicKey= "";
    // 日志记录目录
    private String logPath = "";
    // RSA2
    private String signType = "";

    private String paymentSuccessUrl = "";

    private String paymentFailureUrl = "";

    public void logResult(String sWord) {
        FileWriter writer = null;
        try {
            writer = new FileWriter(logPath + "alipay_log_" + System.currentTimeMillis()+".txt");
            writer.write(sWord);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
